{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "import numpy as np\n",
    "import h5py\n",
    "import matplotlib.pyplot as plt\n",
    "import scipy\n",
    "from PIL import Image\n",
    "from scipy import ndimage\n",
    "import tensorflow as tf\n",
    "from tensorflow.python.framework import ops\n",
    "from cnn_utils import *\n",
    "\n",
    "%matplotlib inline\n",
    "np.random.seed(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train_orig, Y_train_orig, X_test_orig, Y_test_orig, classes = load_dataset()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y = 2\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP4AAAD8CAYAAABXXhlaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJztfWuQXEeV5nfq0dUvtbr1tCzJtmzLbywZy8bGYIwfrHkEno2A2QFiwrvhCP9hN5jY2RhgN2JjZmM3Av4M7I8NIhwLi38wA4YBbLwsYPzgYeOHjN9vWZYluWW1pO5Wv7u6q3J/VPXNc/JWZmdVd1cZ7vkiOjpvZd7MrHtv1j0nzznfIWMMFApFtpDr9AQUCkX7oQtfocggdOErFBmELnyFIoPQha9QZBC68BWKDEIXvkKRQaxo4RPRrUT0GhEdIKKvrNakFArF2oJadeAhojyA1wHcAuAogKcAfM4Y8/LqTU+hUKwFCis492oAB4wxBwGAiL4P4DYA3oW/YcOQ2bl9e+2AVjDyqmLlE6FAF6mf1VZ+Z1fhWjXXRTtvTvMXJHjGmjuirsEAq9ClqXdy9J1hjI6OLXs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APNGJudTF62dRI0l9AMCbAMaNMUvRK+26P98E8HewfB0bOzQPA+BXRPQ0Ed1Z/6zd96VtVPbtXPiNwoYyaVIgon4A/wLgb4wxE52YgzGmYozZi9ob92oAFzdqtpZzIKJPARgxxjzNP273POq4zhjzftRU0S8S0fVtGNPFiqjsm0E7F/5RADvZ8Q4Aw20c30UUPfhqg4iKqC367xljftzJuQCAMWYctSxI1wAYJKKlUO123J/rAHyaiA4B+D5q4v43OzAPGGOG6/9HAPwEtR/Ddt+XFVHZN4N2LvynAOyu79h2AfgrAPe1cXwX96FGCw7E0oOvEFQLlv42gFeMMf/YqbkQ0WYiGqyXewDcjNom0sMAPtOueRhjvmqM2WGMOQe15+EhY8wX2j0PIuojonVLZQAfA/Ai2nxfjDHvAjhCRBfWP1qisl/9eaz1pomzSfEJAK+jpk/+lzaO+88AjgFYQO1X9Q7UdMkHAbxR/7+hDfP4EGpi6/MAnq3/faLdcwFwOYBn6vN4EcB/rX9+LoAnARwA8EMApTbeoxsA3N+JedTHe67+99LSs9mhZ2QvgP31e/NTAENrMQ/13FMoMgj13FMoMghd+ApFBqELX6HIIHThKxQZhC58hSKD0IWvUGQQuvAVigxCF75CkUH8f1DAf7IiI0e5AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "index = 6\n",
    "plt.imshow(X_train_orig[index])\n",
    "print (\"y = \" + str(np.squeeze(Y_train_orig[:, index])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of training examples = 1080\n",
      "number of test examples = 120\n",
      "X_train shape: (1080, 64, 64, 3)\n",
      "Y_train shape: (1080, 6)\n",
      "X_test shape: (120, 64, 64, 3)\n",
      "Y_test shape: (120, 6)\n"
     ]
    }
   ],
   "source": [
    "X_train = X_train_orig/255.\n",
    "X_test = X_test_orig/255.\n",
    "Y_train = convert_to_one_hot(Y_train_orig, 6).T\n",
    "Y_test = convert_to_one_hot(Y_test_orig, 6).T\n",
    "print (\"number of training examples = \" + str(X_train.shape[0]))\n",
    "print (\"number of test examples = \" + str(X_test.shape[0]))\n",
    "print (\"X_train shape: \" + str(X_train.shape))\n",
    "print (\"Y_train shape: \" + str(Y_train.shape))\n",
    "print (\"X_test shape: \" + str(X_test.shape))\n",
    "print (\"Y_test shape: \" + str(Y_test.shape))\n",
    "conv_layers = {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create placeholder\n",
    "def create_placeholders(n_H0, n_W0, n_C0, n_y):\n",
    "    \"\"\"\n",
    "    为session创建占位符\n",
    "\n",
    "    参数：\n",
    "        n_H0 - 实数，输入图像的高度\n",
    "        n_W0 - 实数，输入图像的宽度\n",
    "        n_C0 - 实数，输入的通道数\n",
    "        n_y  - 实数，分类数\n",
    "\n",
    "    输出：\n",
    "        X - 输入数据的占位符，维度为[None, n_H0, n_W0, n_C0]，类型为\"float\"\n",
    "        Y - 输入数据的标签的占位符，维度为[None, n_y]，维度为\"float\"\n",
    "    \"\"\"\n",
    "    X = tf.placeholder(tf.float32, shape=(None, n_H0, n_W0, n_C0))\n",
    "    Y = tf.placeholder(tf.float32,shape=(None,n_y))\n",
    "\n",
    "    return X,Y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "X = Tensor(\"Placeholder:0\", shape=(?, 64, 64, 3), dtype=float32)\n",
      "Y = Tensor(\"Placeholder_1:0\", shape=(?, 6), dtype=float32)\n"
     ]
    }
   ],
   "source": [
    "X , Y = create_placeholders(64,64,3,6)\n",
    "print (\"X = \" + str(X))\n",
    "print (\"Y = \" + str(Y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#init parameters\n",
    "# 使用tf.contrib.layers.xavier_initializer(seed = 0) 来初始化权值/过滤器W1、W2。\n",
    "# 不需要考虑偏置，因为TensorFlow会考虑到的。\n",
    "# 只需要初始化为2D卷积函数，全连接层TensorFlow会自动初始化的。\n",
    "def initialize_parameters():\n",
    "    \"\"\"\n",
    "    初始化权值矩阵，这里我们把权值矩阵硬编码：\n",
    "    W1 : [4, 4, 3, 8]\n",
    "    W2 : [2, 2, 8, 16]\n",
    "\n",
    "    返回：\n",
    "        包含了tensor类型的W1、W2的字典\n",
    "    \"\"\"\n",
    "    tf.set_random_seed(1)\n",
    "\n",
    "    W1 = tf.get_variable(\"W1\",[4,4,3,8],initializer=tf.contrib.layers.xavier_initializer(seed=0))\n",
    "    W2 = tf.get_variable(\"W2\",[2,2,8,16],initializer=tf.contrib.layers.xavier_initializer(seed=0))\n",
    "\n",
    "    parameters = {\"W1\": W1,\n",
    "                  \"W2\": W2}\n",
    "\n",
    "    return parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "W1 = [ 0.00131723  0.1417614  -0.04434952  0.09197326  0.14984085 -0.03514394\n",
      " -0.06847463  0.05245192]\n",
      "W2 = [-0.08566415  0.17750949  0.11974221  0.16773748 -0.0830943  -0.08058\n",
      " -0.00577033 -0.14643836  0.24162132 -0.05857408 -0.19055021  0.1345228\n",
      " -0.22779644 -0.1601823  -0.16117483 -0.10286498]\n"
     ]
    }
   ],
   "source": [
    "# test\n",
    "tf.reset_default_graph()\n",
    "with tf.Session() as sess_test:\n",
    "    parameters = initialize_parameters()\n",
    "    init = tf.global_variables_initializer()\n",
    "    sess_test.run(init)\n",
    "    print(\"W1 = \" + str(parameters[\"W1\"].eval()[1,1,1]))\n",
    "    print(\"W2 = \" + str(parameters[\"W2\"].eval()[1,1,1]))\n",
    "\n",
    "    sess_test.close()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 前向传播流程\n",
    "# CONV2D→RELU→MAXPOOL→CONV2D→RELU→MAXPOOL→FULLCONNECTED\n",
    "def forward_propagation(X,parameters):\n",
    "    \"\"\"\n",
    "    实现前向传播\n",
    "    CONV2D -> RELU -> MAXPOOL -> CONV2D -> RELU -> MAXPOOL -> FLATTEN -> FULLYCONNECTED\n",
    "\n",
    "    参数：\n",
    "        X - 输入数据的placeholder，维度为(输入节点数量，样本数量)\n",
    "        parameters - 包含了“W1”和“W2”的python字典。\n",
    "\n",
    "    返回：\n",
    "        Z3 - 最后一个LINEAR节点的输出\n",
    "\n",
    "    \"\"\"\n",
    "    W1 = parameters['W1']\n",
    "    W2 = parameters['W2']\n",
    "\n",
    "    #Conv2d : 步伐：1，填充方式：“SAME”\n",
    "    Z1 = tf.nn.conv2d(X,W1,strides=[1,1,1,1],padding=\"SAME\")\n",
    "    #ReLU ：\n",
    "    A1 = tf.nn.relu(Z1)\n",
    "    #Max pool : 窗口大小：8x8，步伐：8x8，填充方式：“SAME”\n",
    "    P1 = tf.nn.max_pool(A1,ksize=[1,8,8,1],strides=[1,8,8,1],padding=\"SAME\")\n",
    "\n",
    "    #Conv2d : 步伐：1，填充方式：“SAME”\n",
    "    Z2 = tf.nn.conv2d(P1,W2,strides=[1,1,1,1],padding=\"SAME\")\n",
    "    #ReLU ：\n",
    "    A2 = tf.nn.relu(Z2)\n",
    "    #Max pool : 过滤器大小：4x4，步伐：4x4，填充方式：“SAME”\n",
    "    P2 = tf.nn.max_pool(A2,ksize=[1,4,4,1],strides=[1,4,4,1],padding=\"SAME\")\n",
    "\n",
    "    #一维化上一层的输出\n",
    "    P = tf.contrib.layers.flatten(P2)\n",
    "\n",
    "    #全连接层（FC）：使用没有非线性激活函数的全连接层\n",
    "    Z3 = tf.contrib.layers.fully_connected(P,6,activation_fn=None)\n",
    "\n",
    "    return Z3\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Z3 = [[ 1.4416987  -0.24909692  5.450499   -0.2618962  -0.20669901  1.3654671 ]\n",
      " [ 1.4070845  -0.02573182  5.0892797  -0.4866991  -0.4094069   1.2624857 ]]\n"
     ]
    }
   ],
   "source": [
    "tf.reset_default_graph()\n",
    "np.random.seed(1)\n",
    "\n",
    "with tf.Session() as sess_test:\n",
    "    X,Y = create_placeholders(64,64,3,6)\n",
    "    parameters = initialize_parameters()\n",
    "    Z3 = forward_propagation(X,parameters)\n",
    "\n",
    "    init = tf.global_variables_initializer()\n",
    "    sess_test.run(init)\n",
    "\n",
    "    a = sess_test.run(Z3,{X: np.random.randn(2,64,64,3), Y: np.random.randn(2,6)})\n",
    "    print(\"Z3 = \" + str(a))\n",
    "\n",
    "    sess_test.close()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def compute_cost(Z3,Y):\n",
    "    \"\"\"\n",
    "    计算成本\n",
    "    计算softmax的损失函数:\n",
    "    tf.nn.softmax_cross_entropy_with_logits(logits = Z3 , lables = Y)\n",
    "    tf.reduce_mean：计算平均值\n",
    "    参数：\n",
    "        Z3 - 正向传播最后一个LINEAR节点的输出，维度为（6，样本数）。\n",
    "        Y - 标签向量的placeholder，和Z3的维度相同\n",
    "\n",
    "    返回：\n",
    "        cost - 计算后的成本\n",
    "\n",
    "    \"\"\"\n",
    "\n",
    "    cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=Z3,labels=Y))\n",
    "\n",
    "    return cost"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From <ipython-input-13-fe84f9e71528>:17: softmax_cross_entropy_with_logits (from tensorflow.python.ops.nn_ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "\n",
      "Future major versions of TensorFlow will allow gradients to flow\n",
      "into the labels input on backprop by default.\n",
      "\n",
      "See `tf.nn.softmax_cross_entropy_with_logits_v2`.\n",
      "\n",
      "cost = 4.6648703\n"
     ]
    }
   ],
   "source": [
    "#test\n",
    "tf.reset_default_graph()\n",
    "\n",
    "with tf.Session() as sess_test:\n",
    "    np.random.seed(1)\n",
    "    X,Y = create_placeholders(64,64,3,6)\n",
    "    parameters = initialize_parameters()\n",
    "    Z3 = forward_propagation(X,parameters)\n",
    "    cost = compute_cost(Z3,Y)\n",
    "\n",
    "    init = tf.global_variables_initializer()\n",
    "    sess_test.run(init)\n",
    "    a = sess_test.run(cost,{X: np.random.randn(4,64,64,3), Y: np.random.randn(4,6)})\n",
    "    print(\"cost = \" + str(a))\n",
    "\n",
    "    sess_test.close()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构建模型\n",
    "# 创建占位符、初始化参数、前向传播、成本、反向传播、优化器\n",
    "def model(X_train, Y_train, X_test, Y_test, learning_rate=0.009, \n",
    "         num_epochs=100,minibatch_size=64,print_cost=True,isPlot=True):\n",
    "    \"\"\"\n",
    "    使用TensorFlow实现三层的卷积神经网络\n",
    "    CONV2D -> RELU -> MAXPOOL -> CONV2D -> RELU -> MAXPOOL -> FLATTEN -> FULLYCONNECTED\n",
    "\n",
    "    参数：\n",
    "        X_train - 训练数据，维度为(None, 64, 64, 3)\n",
    "        Y_train - 训练数据对应的标签，维度为(None, n_y = 6)\n",
    "        X_test - 测试数据，维度为(None, 64, 64, 3)\n",
    "        Y_test - 训练数据对应的标签，维度为(None, n_y = 6)\n",
    "        learning_rate - 学习率\n",
    "        num_epochs - 遍历整个数据集的次数\n",
    "        minibatch_size - 每个小批量数据块的大小\n",
    "        print_cost - 是否打印成本值，每遍历100次整个数据集打印一次\n",
    "        isPlot - 是否绘制图谱\n",
    "\n",
    "    返回：\n",
    "        train_accuracy - 实数，训练集的准确度\n",
    "        test_accuracy - 实数，测试集的准确度\n",
    "        parameters - 学习后的参数\n",
    "    \"\"\"\n",
    "    ops.reset_default_graph()  #能够重新运行模型而不覆盖tf变量\n",
    "    tf.set_random_seed(1)    \n",
    "    seed = 3                 #指定numpy的随机种子\n",
    "    (m , n_H0, n_W0, n_C0) = X_train.shape\n",
    "    n_y = Y_train.shape[1]\n",
    "    costs = []\n",
    "\n",
    "    #创建占位符\n",
    "    X , Y = create_placeholders(n_H0, n_W0, n_C0, n_y)\n",
    "\n",
    "    #初始化参数\n",
    "    parameters = initialize_parameters()\n",
    "\n",
    "    #前向传播\n",
    "    Z3 = forward_propagation(X,parameters)\n",
    "\n",
    "    #计算成本\n",
    "    cost = compute_cost(Z3,Y)\n",
    "\n",
    "    #反向传播，由于框架已经实现了反向传播，我们只需要选择一个优化器就行了\n",
    "    optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)\n",
    "\n",
    "    #全局初始化所有变量\n",
    "    init = tf.global_variables_initializer()\n",
    "\n",
    "    #开始运行\n",
    "    with tf.Session() as sess:\n",
    "        #初始化参数\n",
    "        sess.run(init)\n",
    "        #开始遍历数据集\n",
    "        for epoch in range(num_epochs):\n",
    "            minibatch_cost = 0\n",
    "            num_minibatches = int(m / minibatch_size) #获取数据块的数量\n",
    "            #seed = seed + 1   #注释掉\n",
    "            minibatches = random_mini_batches(X_train,Y_train,minibatch_size,seed) \n",
    "\n",
    "            #对每个数据块进行处理\n",
    "            for minibatch in minibatches:\n",
    "                #选择一个数据块\n",
    "                (minibatch_X,minibatch_Y) = minibatch\n",
    "                #最小化这个数据块的成本\n",
    "                _ , temp_cost = sess.run([optimizer,cost],feed_dict={X:minibatch_X, Y:minibatch_Y})\n",
    "\n",
    "                #累加数据块的成本值\n",
    "                minibatch_cost += temp_cost / num_minibatches\n",
    "\n",
    "            #是否打印成本\n",
    "            if print_cost:\n",
    "                #每5代打印一次\n",
    "                if epoch % 10 == 0:\n",
    "                    print(\"当前是第 \" + str(epoch) + \" 代，成本值为：\" + str(minibatch_cost))\n",
    "\n",
    "            #记录成本\n",
    "            if epoch % 5 == 0:\n",
    "                costs.append(minibatch_cost)\n",
    "\n",
    "        #数据处理完毕，绘制成本曲线\n",
    "        if isPlot:\n",
    "            plt.plot(np.squeeze(costs))\n",
    "            plt.ylabel('cost')\n",
    "            plt.xlabel('iterations (per tens)')\n",
    "            plt.title(\"Learning rate =\" + str(learning_rate))\n",
    "            plt.show()\n",
    "\n",
    "        #开始预测数据\n",
    "        # 计算当前的预测情况\n",
    "        predict_op = tf.arg_max(Z3,1)\n",
    "        \n",
    "        # 返回的是Z3中的最大值的索引号，如果vector是一个向量，那就返回一个值，\n",
    "        # 如果是一个矩阵，那就返回一个向量，\n",
    "        # 这个向量的每一个维度都是相对应矩阵行的最大值元素的索引号。\n",
    "        corrent_prediction = tf.equal(predict_op , tf.arg_max(Y,1))\n",
    "\n",
    "        ##计算准确度\n",
    "        accuracy = tf.reduce_mean(tf.cast(corrent_prediction,\"float\"))\n",
    "        print(\"corrent_prediction accuracy= \" + str(accuracy))\n",
    "\n",
    "        train_accuracy = accuracy.eval({X: X_train, Y: Y_train})\n",
    "        test_accuary = accuracy.eval({X: X_test, Y: Y_test})\n",
    "\n",
    "        print(\"训练集准确度：\" + str(train_accuracy))\n",
    "        print(\"测试集准确度：\" + str(test_accuary))\n",
    "\n",
    "        return (train_accuracy,test_accuary,parameters)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前是第 0 代，成本值为：1.9207376539707184\n",
      "当前是第 10 代，成本值为：1.3624227494001389\n",
      "当前是第 20 代，成本值为：1.0148674063384533\n",
      "当前是第 30 代，成本值为：0.8729662001132965\n",
      "当前是第 40 代，成本值为：0.8108688183128834\n",
      "当前是第 50 代，成本值为：0.7674748562276363\n",
      "当前是第 60 代，成本值为：0.7473210655152798\n",
      "当前是第 70 代，成本值为：0.6817025877535343\n",
      "当前是第 80 代，成本值为：0.6766474470496178\n",
      "当前是第 90 代，成本值为：0.626325087621808\n",
      "当前是第 100 代，成本值为：0.6269172057509422\n",
      "当前是第 110 代，成本值为：0.5729277990758419\n",
      "当前是第 120 代，成本值为：0.5514095742255449\n",
      "当前是第 130 代，成本值为：0.549028679728508\n",
      "当前是第 140 代，成本值为：0.5352977123111486\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEWCAYAAACJ0YulAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3Xl8XXWd//HXJ0vTJE2TZu3eBLpCaQsUyj4sBSoKCAMIKALKMKg4Ds78RmZ+jjA4qKPiqMMPFLVURRYVhkGEgiBQoJTSQlu6Qdd0TbO1aZtmz+f3xz0N106SJm1uTu697+fjcR65y/ee+/ly6X3fc873fI+5OyIiIgApYRcgIiIDh0JBREQ6KBRERKSDQkFERDooFEREpINCQUREOigUJCGZ2fNmdmPYdYjEG4WC9Ckz22xms8Ouw90/5u6/DLsOADN71cxu6Yf3yTCzuWa218wqzOyrh2l/R9CuLnhdRtRzpWb2ipkdMLO10Z9p8D7/aWY7zGy3mT1gZumx7Jv0H4WCxB0zSwu7hoMGUi3A3cAEYBxwHvBPZjans4ZmdjFwJ3ABUAocA/xbVJPHgPeAAuD/Ar83s6LguTuBmcBUYCJwEvD1vu2KhMbdtWjpswXYDMzu4rlPAMuAPcBCYFrUc3cCG4B9wGrgiqjnbgLeBP4TqAX+PXjsDeD7wG5gE/CxqNe8CtwS9fru2pYBC4L3fgn4f8AjXfThXGAb8DWgAvg1MAx4FqgK1v8sMDpofy/QBjQC+4H7g8cnA38K+vMBcE0f/LffDlwUdf+bwONdtH0U+F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3wHOA/7Yg/eXBKYhqSIxYGY/InLQ9qVg/P+z7v77w7wsNGaWQSS0zvKPLuEoSUi7j0Ri41tAVthF9MJY4E4FgmhLQUREOmhLQUREOigURESkg0JBREQ6KBRERKSDQkFERDr8f4ysQEvDF4Q0AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From <ipython-input-15-d82b144d5da5>:91: arg_max (from tensorflow.python.ops.gen_math_ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use `argmax` instead\n",
      "corrent_prediction accuracy= Tensor(\"Mean_1:0\", shape=(), dtype=float32)\n",
      "训练集准确度：0.80925924\n",
      "测试集准确度：0.64166665\n"
     ]
    }
   ],
   "source": [
    "_, _, parameters = model(X_train, Y_train, X_test, Y_test,num_epochs=150)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
